<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <base href="<%=basePath %>">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户列表</title>
    <link href="static/css/bootstrap.min.css" rel="stylesheet">
    <link href="static/css/font-awesome.css" rel="stylesheet">
    <link href="static/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="static/css/animate.css" rel="stylesheet">
    <link href="static/css/style.css" rel="stylesheet">
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>用户列表</h5>
                <div class="ibox-tools">
                    <a class="collapse-link">
                        <i class="fa fa-chevron-up"></i>
                    </a>
                    <a class="close-link">
                        <i class="fa fa-times"></i>
                    </a>
                </div>
            </div>
            <div class="ibox-content">
                <div class="col-sm-6 float-left">   
                    <a href="view/user/addUI.shtml" class="btn btn-w-m btn-info" type="button">
                        <i class="fa fa-plus" aria-hidden="true"></i>&nbsp;新增用户
                    </a>
                </div>
                <table id="userList" data-toggle="table"
                    data-url="user/getList.shtml"
                    data-query-params=queryParams data-query-params-type="limit"
                    data-pagination="true"
                    data-side-pagination="server" data-pagination-loop="false">
                    <thead>
                        <tr>
                            <th data-field="uId">用户编号</th>
                            <th data-field="uAccount">用户账号</th>
                            <th data-field="uNickname">用户昵称</th>
                            <th data-field="uEmail">用户邮箱</th>
                            <th data-field="editTime">用户更新时间</th>
                            <th data-field="action" data-formatter="actionFormatter"
                                data-events="actionEvents">操作</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
    <!-- 全局js -->
    <script src="static/js/jquery.min.js"></script>
    <script src="static/js/bootstrap.min.js"></script>
    <!-- layer javascript -->
    <script src="static/js/plugins/layer/layer.min.js"></script>
    <!-- 自定义js -->
    <script src="static/js/content.js"></script>
    <!-- Bootstrap table -->
    <script src="static/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="static/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
    <script src="static/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script>
        function actionFormatter(value, row, index) {
            return ['<a class="btn btn-primary btn-xs" id="edit" type="button"><i class="fa fa-paste" aria-hidden="true"></i>&nbsp;编辑</a>',
                '&nbsp;&nbsp;',
                '<a class="btn btn-primary btn-xs" id="delete" type="button"><i class="fa fa-trash" aria-hidden="true"></i>&nbsp;删除</a>'].join(''); 
        };
        window.actionEvents = {             
                'click #edit' : function(e, value, row, index) {
                    var userId = row.uId;
                    location.href = "view/user/editUI.shtml?userId=" + userId;
                },
                'click #delete' : function(e, value, row, index) {
                    layer.confirm('确定删除该单位？', {
                          btn: ['确定', '取消'] 
                        },
                        function(index){
                            layer.close(index);
                            $.ajax({
                                type: 'POST',
                                async: true,
                                url: 'user/delete.shtml',
                                data: {
                                    "userId": row.uId          
                                },
                                success: function (data) {
                                    location.replace(location.href);                             
                                },
                                error: function () {
                                    alert("系统出现问题，请联系管理员");
                                },
                                dataType: 'json'
                            });
                        }, 
                        function(){
                            layer.msg('取消操作');
                        }
                    );
                },
            };
            
            function queryParams(params) {
                var temp = { limit: 10, offset: params.offset };
                return temp;
            };
            
            function getIdSelections() {
                var $userList = $('#userList');
                return $.map($userList.bootstrapTable('getSelections'), function (row) {
                    return row.uId
                });
            }
            
            
    </script>
</body>
</html>